<?php
class PhysiciansController extends AppController{
	public function insert($data){
		$this->data['Physician']['claimid']=$data[0];
		$this->data['Physician']['firstname']=$data[1];
		$this->data['Physician']['middlename']=$data[2];
		$this->data['Physician']['lastname']=$data[3];
		$this->data['Physician']['accreditationcode']=$data[4];
		$this->data['Physician']['serviceperformed']='Daily visit';
		$this->data['Physician']['dailyrate']=$data[5];
		$this->data['Physician']['dayscovered']=$data[6];
		$this->data['Physician']['actualcharge']=str_replace(',', '', $data[7]);
		$this->data['Physician']['benifitclaim']=str_replace(',', '', $data[8]);
		$this->data['Physician']['status']=1;

		$this->Physician->create();
		$this->Physician->save($this->data);
	}
	function setStatus($id, $status){
		$this->data['Physician']['id']=$id;
		$this->data['Physician']['status']=$status;
		
		$this->Physician->save($this->data);
	}
	function setRateDay(){
		$rate=$_POST['rate'];
		$day=$_POST['day'];
		$id=$_POST['id'];
		
		$actualcharge=$rate*$day;
		
		$this->data['Physician']['id']=$id;
		$this->data['Physician']['dailyrate']=$rate;
		$this->data['Physician']['dayscovered']=$day;
		$this->data['Physician']['actualcharge']=$actualcharge;
		
		$this->Physician->save($this->data);
	}
	function getDailyRate($patientid){
		App::import('Model', 'Patient');
		$patient=new Patient();
		$pat=$patient->findById($patientid);
		$claimid=$pat['Patient']['accreditation'].				
				$pat['Patient']['membernumber'].
				date('Ymd',strtotime($pat['Patient']['dateadmitted'])).
				date('Hi',strtotime($pat['Patient']['timeadmitted']));
				
		$casetype=$this->requestAction('/casetypes/getCaseType/'.$pat['Patient']['finaldiagnosis']);				
		
		/**		 
		App::import('Model', 'DailyvisitRate');
		App::import('Model', 'Accreditation');
		$accreditation=new Accreditation();
		$dailyrate=new DailyvisitRate();
		*/
		$code="";
		$data=$this->Physician->find('all', array('conditions'=>array('claimid'=>$claimid)));
		foreach($data as $row){
			$code.=$row['Physician']['accreditationcode']." ";
			if($this->getGroup($code)==1){
				
			}
		}		
		return $code;
	}
	private function _getDailyRate($code, $casetype){
		if($this->getGroup($code)==1){
			
		}
		else if($this->getGroup($code)==2){
			
		}
	}
	private function getGroup($code){
		$code=substr($code, 1, 1);
		if($code=='2' || $code=='3' || $code=='4'){
			//Spcialist
			return 1;
		}
		else if($code=='1' || $code=='5' || $code=='6'){
			//General Practitioner
			return 2;
		}
		else{
			return 0;
		}
	}
}
?>